package scau.mis4.chanyulin.tools.utils;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by cyl on 2017/3/14
 * XML文件操作工具类
 */

public class XmlUtils {

    /**
     * 获取配置文件根节点
     * @param path 路径
     * @param isResource 是否为项目资源文件
     */
    public static Element getConfigElement(String path, boolean isResource) throws IOException, DocumentException {
        InputStream in;
        if (isResource)
            in = XmlUtils.class.getResourceAsStream(path);
        else
            in = new FileInputStream(path);
        SAXReader reader = new SAXReader();
        Document doc;
        doc = reader.read(in);
        in.close();
        return doc.getRootElement();
    }

}
